Highlight Controls

Highlight a Record Row Based on a Condition

Description
This customization demonstrates how to highlight a record row based on a condition.
Variables
RecordControl
Select a record control
Conditional Field Control
Field that controls the appearence of the row
Applies to
RecordControl class
Code
 
/// 
/// Highlights the record in the PreRender event
/// 
private void RecordControl_PreRender(object sender, System.EventArgs e) 
{
    // Compare value to determine if you want to highlight the background of the row.
    // For example, if ${Conditional Field Control} > 25, then, highlight.
    // Note: You can also check if the field value equals a certain string,
    // e.g, ${Conditional Field Control}.Text = "Yes".
    if (double.Parse(this.${Conditional Field Control}.Text) == 25) 
    {
        // Find the record row the field value is on.
        System.Web.UI.HtmlControls.HtmlTableRow recordRow; 
        recordRow = (System.Web.UI.HtmlControls.HtmlTableRow)this.FindControl("MyTR"); 

        // Set the background color on the record row in RGB format.
        string color = "#ffff00"; 

        // For each cell, set the background color.
        foreach (System.Web.UI.HtmlControls.HtmlTableCell recordRowCell in recordRow.Cells) 
        {   
            // Override the record row background color -- since each data cell uses a 
            // style (by default: table_cell or table_cellr)
            recordRowCell.Style.Add("background-color", color); 
        }     
    }
}
     
Applies to
CSharpRecordControlConstructor class
Code
 
    // The following line will be inserted inside the
    // constructor for page class.
    this.PreRender += new System.EventHandler(RecordControl_PreRender);    
     

Terms of Service Privacy Statement